package com.jy.adscm.operation.mscyb.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqbzPartsassemblydetail;
import com.jy.adscm.operation.mscyb.bean.JqylMaterial;
import com.jy.adscm.operation.mscyb.service.JqbzPartsassemblydetailService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2018-11-26
 */
@Deprecated
@RestController
@RequestMapping("/adscm/operation/jqbzPartsassemblydetail")
public class JqbzPartsassemblydetailController {
    @Autowired
    JqbzPartsassemblydetailService  jqbzPartsassemblydetailService;
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;

    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody JqbzPartsassemblydetail jqbzPartsassemblydetail, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = jqbzPartsassemblydetailService.insertJqbzPartsassemblydetail(jqbzPartsassemblydetail,token);
        return new SimpleCoreResponse("200","新增成功",insert);
    }

    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id)throws AdscmSystemException {
        boolean result = jqbzPartsassemblydetailService.deleteById(id);
        return new  SimpleCoreResponse("200","删除成功",result);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody JqbzPartsassemblydetail jqbzPartsassemblydetail, HttpServletRequest request) throws AdscmSystemException{
        Boolean result = jqbzPartsassemblydetailService.updateJqbzPartsassemblydetail(jqbzPartsassemblydetail);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
    @RequestMapping("selectByTid/{tid}")
    public  SimpleCoreResponse  selectByTid(@PathVariable String tid) throws  AdscmSystemException{
        List<JqbzPartsassemblydetail> JqbzPartsassemblydetails = jqbzPartsassemblydetailService.selectByTid(tid);
        return  new SimpleCoreResponse("200","查询成功",JqbzPartsassemblydetails);
    }
    @RequestMapping("queryMaterial")
    public  SimpleCoreResponse  queryMaterial() throws  AdscmSystemException{
        List<JqylMaterial>  jqylMaterials= jqbzPartsassemblydetailService.queryMaterial();
        return  new SimpleCoreResponse("200","查询成功",jqylMaterials);
    }

}

